package com.itheima;

import java.util.*;

/**
 * @auther Macrydy
 * @date 2020/7/6 18:54
 */
public class Demo02 {
    public static void main(String[] args) {
        List<Student> list = new ArrayList<>();
        list.add(new Student(1, "张亮", 98));
        list.add(new Student(2, "贾明明", 86));
        list.add(new Student(3, "贺晓光", 90));
        list.add(new Student(4, "甜甜", 89));
        list.add(new Student(4, "丽丽", 76));

        //利用Collections中的sort方法将5个学生按照比赛成绩进行排序
        Collections.sort(list, new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return o2.getScore()-o1.getScore();
            }
        });

        System.out.println(list);

        // 删除前三名之后的学生
        for (int i = 0; i < list.size(); i++) {
            if (i>2){
                list.remove(i);
                i--;
            }
        }
        //打印前三名学生信息
        System.out.println(list);

    }
}

class Student{
    private int id;
    private String name;
    private int score;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getScore() {
        return score;
    }

    public void setScore(int score) {
        this.score = score;
    }

    public Student(int id, String name, int score) {
        this.id = id;
        this.name = name;
        this.score = score;
    }

    public Student() {
    }

    @Override
    public String toString() {
        return "Student{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", score=" + score +
                '}';
    }
}
